// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "HealthComponent.generated.h"


DECLARE_DYNAMIC_MULTICAST_DELEGATE_SixParams(FHealthChangedSignature, UHealthComponent*, HealthComponent, float, Health, float ,Damage, const class UDamageType* ,DamageType, class AController* ,InstigatedBy, AActor* ,DamageCauser);


UCLASS( ClassGroup=(COOP), meta=(BlueprintSpawnableComponent) )
class SIMPLE_API UHealthComponent : public UActorComponent
{
	GENERATED_BODY()

public:	
	// Sets default values for this component's properties
	UHealthComponent();

protected:
	// Called when the game starts
	virtual void BeginPlay() override;

	UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = Simple, Replicated)
	float Health;

	UFUNCTION()
	void InitHealth();

	UFUNCTION()
	void HandleOnTakeAnyDamage(AActor* DamagedActor, float Damage, const class UDamageType* DamageType, class AController* InstigatedBy, AActor* DamageCauser);

	UFUNCTION(Reliable, Server, WithValidation)
	void ServerUpdateHealth(float HealthValue);
public:	
	// Called every frame
	virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;

	UFUNCTION(BlueprintPure, Category = Simple)
	float GetMaxHealth() const;


	
public:
	virtual void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override;

	UPROPERTY(BlueprintAssignable, Category = Simple)
	FHealthChangedSignature OnHealthChanged;

	UFUNCTION(BlueprintCallable, Category = Simple)
	void UpdateHealth(float HealthValue);
};
